<template>
	<div>
		<!-- <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom:20px;">
			<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>书籍管理</el-breadcrumb-item>
		</el-breadcrumb> -->

		<el-form :inline="true" :model="param" class="demo-form-inline">
			<el-form-item label="搜索">
				<el-input v-model.trim="param.keyword" placeholder="搜索"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" >查询</el-button>
				<el-button type="primary" >新增</el-button>
			</el-form-item>
		</el-form>

		<el-table :data="tableData" :stripe="true" :border="true" @sort-change="onSortChange">
			<el-table-column prop="createTime" label="创建时间" sortable="custom"></el-table-column>
			<el-table-column prop="name" label="名称" sortable="custom"></el-table-column>
			<el-table-column prop="publishTime" label="出版时间" sortable="custom"></el-table-column>
			<el-table-column prop="typeName" label="类别"></el-table-column>
			<el-table-column prop="deptName" label="所属单位"></el-table-column>
			<el-table-column prop="statusName" label="状态"></el-table-column>
			<el-table-column prop label>
				<template slot-scope="scope">
					<el-button size="mini" @click="$router.push('book/'+scope.row.id)">编辑</el-button>
					<el-button size="mini" type="danger" @click="deletes(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-pagination
			style="float:right; margin-top:10px"
			background
			layout="prev, pager, next, total"
			:total="total"
			:page-size="param.pageSize"
			:current-page="param.pageNum"
			@current-change="onCurrentChanged"
		></el-pagination>
	</div>
</template>
<script>
import TreeSelect from "./../comm/comm-treeSelect.vue";
export default {
	name: 'books',
	data: function() {
		return {
			tableData: [],
			total: 0,
			param: {
				pageSize: 3,
				pageNum: 1,
				orderProp: "",
				orderDir: "",
				keyword: ""
			}
		};
	},
	created: function() {
		// this.query();
	},
	activated: function() {
		// this.query();
	},
	methods: {
		onSortChange: function(param) {
			if (param.prop) {
				this.param.orderProp = param.prop;
				this.param.orderDir = param.order.split("ending")[0];
			} else {
				this.param.orderProp = null;
				this.param.orderDir = null;
			}
			this.query();
		},
		onCurrentChanged: function(param) {
			this.param.pageNum = param;
			this.query();
		},
		query: function() {
			var that = this;
			this.$axios
				.get("../book/page", {
					params: that.param
				})
				.then(resp => {
					if (resp.data.pageNum && resp.data.pageNum != that.param.pageNum) {
						return;
					}
					that.tableData = resp.data.list;
					that.total = resp.data.total;
				});
		},
		deletes: function(id) {
			var that = this;
			that
				.$confirm("确认要删除吗", "提示", {})
				.then(() => {
					that.$axios.delete("../book/one/" + id).then(resp => {
						that.$message.success("删除成功");
						that.query();
					});
				})
				.catch(() => {});
		}
	}
};
</script>
<style scoped>
</style>

